# 测试发送请求接口
import json

import requests

from entity.QTemplate import QTemplate
from entity.Question import Question
from utils.MAC import get_mac_address

ip = "localhost"
url ='http://'+ip+':9000/'
def test_connect():

    response = requests.get(
        'http://'+ip+':9000/test/'
    )
    print(response.json())


def publish_q_template(qtEntity):

    template_name = qtEntity.get_template_name()
    creator_id = get_mac_address()
    num_questions =qtEntity.get_num_questions()
    questions = qtEntity.get_questions()
    timer_duration =qtEntity.get_timer_duration()

    response = requests.post(
        url+"publish/",
        data={"template_name":template_name,
              "creator_id":creator_id,
              "num_questions":num_questions,
              "questions":questions,
              "timer_duration":timer_duration}
    )

    return response.json().get('template_uuid')


def find_qt_req(template_uuid):
    response = requests.get(
        url+"findByTemplateUUID/"+"?template_uuid="+str(template_uuid),
    )
    return response.json().get("data")


def write_qt_req(qtEntity):
    user_id =get_mac_address()
    template_uuid = qtEntity.get_template_uuid()
    answers = qtEntity.get_questions()
    response = requests.post(
        url+'writeQT/',
        data={"user_id":user_id,
              "template_name":template_uuid,
              "answers":answers}
    )
    return response.json().get('msg')


def show_create_qt_req(creator_id):
    response = requests.get(
        url+'showCreatedQuestions/'+'?creator_id='+str(creator_id)
    )
    return response.json().get('data')


def show_join_qt_req(user_id):
    response = requests.get(
        url+'showJoinQuestions/'+"?user_id="+str(user_id)
    )
    return response.json().get('data'),response.json().get('status'),response


def sum_data_qt_req(template_uuid):
    response = requests.get(
        url+'sumData/'+"?template_uuid="+str(template_uuid)
    )
    return response.json().get('data'),response.json().get('userId')
# def publish_q_template1():
#

#
#     response = requests.post(
#         'http://192.168.1.197:9000/publish/',
#         data={qtData.get_template_json_formate()}
#     )
#     print(response.json().get("template_uuid"))


if __name__ == '__main__':
    question1 = Question("1xccxvdvdf1")
    question2 = Question("1dfghgdf")
    question3 = Question("1qwewqe")
    qtData = QTemplate("1das",
                       3,
                       [question1.get_question_json_formate(),
                        question2.get_question_json_formate(),
                        question3.get_question_json_formate()],
                       "2024-07-11 12:11:12")

# print(test_connect())
    # print(publish_q_template(qtData))
    # print(find_qt_req('c013900e-b113-4e98-b88a-8d562fadbbd8'))
    # print(write_qt_req(qtData))
    # print(show_create_qt_req('c013900e-b113-4e98-b88a-8d562fadbbd8'))
    # print(show_join_qt_req(get_mac_address()))
    # print(sum_data_qt_req('c013900e-b113-4e98-b88a-8d562fadbbd8'))
    # output_excel('c013900e-b113-4e98-b88a-8d562fadbbd8')
    # print(type(sum_data_qt_req('c013900e-b113-4e98-b88a-8d562fadbbd8')))
    # Output_Excel(sum_data_qt_req('c013900e-b113-4e98-b88a-8d562fadbbd8'))